package com.harry.service;

import com.harry.mapper.DoctorMapper;
import com.harry.pojo.MedicineRepo;
import com.harry.pojo.ScheduleRecord;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;

@Service
public class DoctorService
{
    @Resource
    DoctorMapper doctorMapper;

    public String setSchedule(String open_id, Timestamp start_time, int capacity)
    {
        //获取doctor_id
        Integer doctor_id = doctorMapper.getDoctorId(open_id);
        if(doctor_id == null)
            return "doctor not registered";
        //判断是否已经设置
        if(doctorMapper.getSingleSchedule(doctor_id, start_time) != null)
        {
            return "schedule already set";
        }
        else
        {
            doctorMapper.setSchedule(doctor_id, start_time, capacity);
            return "success";
        }
    }

    public List<ScheduleRecord> getSchedule(String open_id)
    {
        int doctor_id = doctorMapper.getDoctorId(open_id);
        return doctorMapper.getSchedule(doctor_id);
    }

    public List<ScheduleRecord> getScheduleByDoctorId(int doctor_id)
    {

        return doctorMapper.getSchedule(doctor_id);
    }

    public List<MedicineRepo> getMedicineRepo()
    {
        return doctorMapper.getMedicineRepo();
    }

    public void addMedicine(int medicine_id, int amount)
    {
        doctorMapper.addMedicine(medicine_id, amount);
    }
}
